package com.supcon.exchangedata.repository.master.impl;

import com.supcon.exchangedata.pojo.entity.oracle.BaseGeoArea;
import com.supcon.exchangedata.pojo.entity.oracle.BaseGeoAreaDetail;
import com.supcon.exchangedata.pojo.entity.oracle.CtBusRouteStation;
import com.supcon.exchangedata.pojo.entity.oracle.GisPoint;
import com.supcon.exchangedata.repository.master.MasterBusRoutesStationRepository;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: yangbin
 * @Date: 2022/12/27/15:58
 * @Description:
 */

public class MasterBusRoutesStationRepositoryImpl implements MasterBusRoutesStationRepository {
    @PersistenceContext
    private EntityManager entityManager;

    @Override
    @Transactional
    public void batchAll(List<CtBusRouteStation> ctBusRouteStationList) {
        if (!CollectionUtils.isEmpty(ctBusRouteStationList)) {
            for (CtBusRouteStation ctBusRouteStation : ctBusRouteStationList) {
                try {
                    entityManager.persist(ctBusRouteStation);
                } catch (Exception e) {
                }
            }
            entityManager.flush();
            entityManager.clear();
        }
    }

    @Override
    @Transactional
    public List<BaseGeoArea> batchBaseGeoAll(List<BaseGeoArea> baseGeoAreaList) {

        if (!CollectionUtils.isEmpty(baseGeoAreaList)) {
            for (BaseGeoArea ctBusRouteStation : baseGeoAreaList) {
                try {
                    entityManager.persist(ctBusRouteStation);
                } catch (Exception e) {
                }
            }
            entityManager.flush();
            entityManager.clear();
        }
        return baseGeoAreaList;
    }

    @Override
    @Transactional
    public void batchBaseGeoDetailAll(List<BaseGeoAreaDetail> baseGeoAreaListDetail) {
        if (!CollectionUtils.isEmpty(baseGeoAreaListDetail)) {
            for (BaseGeoAreaDetail ctBusRouteStation : baseGeoAreaListDetail) {
                try {
                    entityManager.persist(ctBusRouteStation);
                } catch (Exception e) {
                }
            }
            entityManager.flush();
            entityManager.clear();
        }
    }

    @Override
    public void batchGisPointDetailAll(List<GisPoint> gisPoints) {
        if (!CollectionUtils.isEmpty(gisPoints)) {
            for (GisPoint ctBusRouteStation : gisPoints) {
                try {
                    entityManager.persist(ctBusRouteStation);
                } catch (Exception e) {
                }
            }
            entityManager.flush();
            entityManager.clear();
        }
    }
}
